package edu.ahut.corejava3;

import java.util.PriorityQueue;
import java.util.Queue;

/**
 * 优先级队列
 */
public class QueueDemo2 {
    public static void main(String[] args) {
        //Queue<Integer> pq = new PriorityQueue<Integer>();//小顶堆 heap sort
        Queue<Integer> pq = new PriorityQueue<>(
                (o1, o2) -> o2 - o1
        );//大顶堆
        for (int i = 0; i < 10; i++) {
            int x = (int) (Math.random() * 100);
            System.out.println("offer " + x + "....");
            pq.offer(x);//入堆
        }

        while (!pq.isEmpty()) {
            System.out.println(pq.peek());//堆顶元素
            pq.poll();//删除堆顶元素
        }


    }
}
